package custom.apache.ibatis.parsing;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.parsing.XNode;
import org.apache.ibatis.parsing.XPathParser;

import java.io.IOException;
import java.io.Reader;
import java.util.List;
import java.util.Properties;

public class XPathTest {
	public static void main(String[] args) throws IOException {
		/*Properties resourceAsProperties = Resources.getResourceAsProperties("mybatis/db.properties");
		System.out.println(resourceAsProperties);*/
		Reader reader = Resources.getResourceAsReader("mybatis/mybatisConfig.xml");
		XPathParser xPathParser = new XPathParser(reader);
		XNode root = xPathParser.evalNode("/configuration");
		XNode environments = root.evalNode("environments");
		List<XNode> children = environments.getChildren();
		for(XNode environment: environments.getChildren()){
			XNode transactionManager = environment.evalNode("transactionManager");
			Properties childrenAsProperties = transactionManager.getChildrenAsProperties();
			System.out.println(childrenAsProperties);
		}
		//System.out.println(bookstore);
	}
}
